package edu.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

@Configuration
public class DruidConfig {

    @Bean
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource druidDataSource() {
        return new DruidDataSource();
    }

    @Bean
    public ServletRegistrationBean statViewServlet() {
        ServletRegistrationBean<StatViewServlet> bean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*");

        /*
         * 配置账号密码
         * */
        HashMap<String, String> initParameters = new HashMap<>();

        /*
         * 配置
         * 配置的key是固定的
         * */
        // 登录账号密码
        initParameters.put("loginUsername", "admin");
        initParameters.put("loginPassword", "175198");
        // 允许谁能访问   ""表示都可以访问
        initParameters.put("allow", "");
        // 禁止谁能访问
        initParameters.put("deny", "");


        bean.setInitParameters(initParameters);

        return bean;
    }


}
